package com.bpmn.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.bpmn.common.annotation.ResponseInfoWrapper;
import com.bpmn.common.pojo.PageResult;
import com.bpmn.system.domain.form.UserForm;
import com.bpmn.system.domain.query.UserQuery;
import com.bpmn.system.domain.vo.UserVo;
import com.bpmn.system.service.ISysUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @author rain
 */
@Tag(name = "应用管理")
@RestController
@RequiredArgsConstructor
@ResponseInfoWrapper
@RequestMapping("/system/user")
public class SysUserController {

    private final ISysUserService userService;

    @Operation(summary = "获取应用列表")
    @GetMapping("/list")
    public PageResult<UserVo> list(UserQuery query) {
        IPage<UserVo> userVoIPage = userService.listUser(query);
        return new PageResult<>(userVoIPage.getRecords(), userVoIPage.getTotal());
    }

    @Operation(summary = "新增应用")
    @PostMapping
    public Boolean add(@RequestBody UserForm user) {
        userService.addUser(user);
        return true;
    }

    @Operation(summary = "修改应用")
    @PutMapping
    public Boolean edit(@RequestBody UserForm user) {
        userService.updateUser(user);
        return true;
    }

    @Operation(summary = "删除应用")
    @DeleteMapping("/{id}")
    public Boolean remove(@PathVariable String id) {
        userService.deleteUser(id);
        return true;
    }

    @Operation(summary = "重置密码")
    @PutMapping("/resetPassword")
    public Boolean resetPassword(@RequestParam String id, @RequestParam String password) {
        userService.resetPassword(id, password);
        return true;
    }

}